$(function () {
    let id = localStorage.getItem("productId");
    findProductClassify();
    selectProductById(id);
})
//查询一条数据库
function selectProductById(id) {
    let data= myAjax('/back/product/updateProduct',{id: id},'get');
    setData(data.productModel);
}
function setData(data) {
    $("#product-name").val(data.name);
    $("#product-description").val(data.content);
    $("#diliver").val(data.diliver);
    $("#averageprice").val(data.averageprice);
    $("#price").val(data.price);
    $("#quality").val(data.quality);
    $("#payment").val(data.payment);
    $("#information").val(data.information);
    $("#productClassify").val(data.classify);
}

function findProductClassify() {
    let data = myAjax('/back/product/findProductClassify','','get');
    data=data.model;
    let html='';
    for (let i=0;i<data.length;i++){
        html +=' <option value="'+data[i].id+'">' + data[i].name + '</option>';
    };
    $("#productClassify").html(html);
}
//更新数据===================================================
function updateProduct() {
    let productid = localStorage.getItem("productId");
    updateProductById(productid);
}
function updateProductById(id) {
    let data1 = new FormData();
    data1.append("classify",$("#productClassify").val());
    data1.append("name",$("#product-name").val());
    data1.append("img",$("#product-img")[0].files[0]);
    data1.append("content",$("#product-description").val());
    data1.append("diliver",$("#diliver").val());
    data1.append("averageprice",$("#averageprice").val());
    data1.append("price",$("#price").val());
    data1.append("quality",$("#quality").val());
    data1.append("payment",$("#payment").val());
    data1.append("information",$("#information").val());
    data1.append("id",id);
    let data = myFileAjax('/back/product/updateProduct',data1,'post');
    data = data.result;
    if (data==1){
        alert("更新成功");
    }else {
        alert("更新失败");
    }
    $("#right").load("/back/html/product/productUpdate.html");

}
//返回上一页面。。。。。。。。
function back() {
    $("#right").load("/back/html/product/productManage.html");
}
